<template>
  <div class="main">
    <div class="center">
      <div class="info">
        <div class="lf">
          <el-image lazy :src="musicData.image" alt="" srcset="" />
        </div>
        <div class="rt">
          <div class="row-two">
            <div class="row">
              <div class="text">{{ musicData.name }}</div>
            </div>
          </div>
          <div class="row-two">
            <div class="row">
              <div class="text">{{ musicData.singer }}</div>
            </div>
          </div>
          <div class="row-two">
            <div class="row">
              <div class="title">专辑</div>
              <div class="dian">：</div>
              <div class="text">{{ musicData.collection }}</div>
            </div>
            <div class="row">
              <div class="title">语种</div>
              <div class="dian">：</div>
              <div class="text">{{ musicData.language }}</div>
            </div>
          </div>
          <div class="row-two">
            <div class="row">
              <div class="title">流派</div>
              <div class="dian">：</div>
              <div class="text">{{ musicData.style }}</div>
            </div>
            <div class="row">
              <div class="title">唱片公司</div>
              <div class="dian">：</div>
              <div class="text">{{ musicData.company }}</div>
            </div>
          </div>
          <div class="row-two">
            <div class="row">
              <div class="title">发行时间</div>
              <div class="dian">：</div>
              <div class="text">{{ musicData.show_time }}</div>
            </div>
          </div>
        </div>
        <div class="play-btn">
          <a
            v-if="
              musicData.url_1 != null &&
              musicData.url_1 != '' &&
              musicData.url_1 != 'None' &&
              musicData.url_1 != undefined
            "
            class="img"
            :href="musicData.url_1"
            target="_blank"
            rel="noopener noreferrer"
          >
            <el-image
              lazy
              :src="require('../assets/images/qq.png')"
              alt=""
              srcset=""
          /></a>
          <a
            v-if="
              musicData.url_2 != null &&
              musicData.url_2 != '' &&
              musicData.url_2 != 'None' &&
              musicData.url_2 != undefined
            "
            class="img"
            :href="musicData.url_2"
            target="_blank"
            rel="noopener noreferrer"
          >
            <el-image
              lazy
              :src="require('../assets/images/kg.png')"
              alt=""
              srcset=""
          /></a>
          <a
            v-if="
              musicData.url_3 != null &&
              musicData.url_3 != '' &&
              musicData.url_3 != 'None' &&
              musicData.url_3 != undefined
            "
            class="img"
            :href="musicData.url_3"
            target="_blank"
            rel="noopener noreferrer"
          >
            <el-image
              lazy
              :src="require('../assets/images/wyy.png')"
              alt=""
              srcset=""
          /></a>
          <a
            v-if="
              musicData.url_4 != null &&
              musicData.url_4 != '' &&
              musicData.url_4 != 'None' &&
              musicData.url_4 != undefined
            "
            class="img"
            :href="musicData.url_4"
            target="_blank"
            rel="noopener noreferrer"
          >
            <el-image
              lazy
              :src="require('../assets/images/kw.png')"
              alt=""
              srcset=""
          /></a>
        </div>
        <!-- <div class="qr-code">
          <el-image lazy src="http://placehold.it/92x92&text=92x92" alt="" srcset="" />
          <p>用手机观看</p>
        </div> -->
      </div>
      <div class="cont">
        <div class="lf">
          <div class="head">歌词</div>
          <div class="body" v-html="musicData.words"></div>
        </div>
        <div class="rt">
          <div class="intro">
            <div class="head">简介</div>
            <div class="body" v-html="musicData.detail"></div>
          </div>
          <div class="related-songs">
            <div class="head">相关热门歌曲</div>
            <div class="body">
              <router-link
                class="item"
                :to="{ name: 'single', query: { id: item.id } }"
                v-for="(item, index) in musicData.orther"
                :key="index"
              >
                <div class="img">
                  <el-image lazy :src="item.image" alt="" />
                </div>
                <h1>{{ item.name }}</h1>
                <p>{{ item.singer }}</p>
              </router-link>
            </div>
          </div>
          <div class="related-mvs">
            <div class="head">相关MV</div>
            <div class="body">
              <div class="item" @click="openMv(musicData.mv)">
                <el-image lazy :src="musicData.mv_image" alt="" />
              </div>
            </div>
          </div>
          <div class="news">
            <router-link
              class="top"
              :to="{ name: 'newsDetail', query: { id: index } }"
              v-for="(item, index) in 2"
              :key="index"
              ref="video"
            >
              <el-image
                lazy
                src="http://placehold.it/460x385&text=460x385"
                alt=""
              />
              <p>许维恩alex为什么离婚?</p>
            </router-link>
          </div>
        </div>
      </div>
    </div>
    <!-- 视频 -->
    <el-dialog
      :visible.sync="dialogVisible"
      width="680px"
      heigth="400px"
      top="20vh"
    >
      <video-player
        class="vjs-default-skin vjs-big-play-centered"
        :options="playerOptions"
      >
      </video-player>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false,
      playerOptions: {
        playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
        autoplay: false, //如果true,浏览器准备好时开始回放。
        muted: false, // 默认情况下将会消除任何音频。
        loop: false, // 导致视频一结束就重新开始。
        preload: "auto", // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: "zh-CN",
        aspectRatio: "16:9", // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        sources: [
          {
            src: "", // 路径
            type: "video/mp4", // 类型
          },
          // {
          //   src: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",
          //   type: "video/webm",
          // },
        ],
        // poster: "../../static/images/test.jpg", //你的封面地址
        // width: document.documentElement.clientWidth,
        notSupportedMessage: "此视频暂无法播放，请稍后再试", //允许覆盖Video.js无法播放媒体源时显示的默认信息。
        controlBar: {
          timeDivider: true,
          durationDisplay: true,
          remainingTimeDisplay: false,
          fullscreenToggle: true, //全屏按钮
        },
      },
      mvdata: [
        {
          mvSrc: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",
          imgSrc: "http://placehold.it/460x187&text=460x187-1",
        },
        {
          mvSrc: "https://media.w3.org/2010/05/sintel/trailer.mp4",
          imgSrc: "http://placehold.it/460x187&text=460x187-2",
        },
      ],
      musicData: [],
    };
  },
  watch: {
    $route: function (to, from) {
      // 监听路由是否变化
      this.getMusic(this.$route.query.id);
    },
  },
  created() {
    const id = this.$route.query.id;
    this.getMusic(id);
  },
  methods: {
    openMv(src) {
      this.dialogVisible = true;
      this.playerOptions.sources[0].src = src;
    },
    getMusic(id) {
      this.$http.getMusic(id).then((res) => {
        if (res.data.code === 0) {
          this.musicData = res.data.data;
        } else {
          this.$message.error("获取失败，请重试！");
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.center {
  width: 1600px;
  margin: 0 auto;
  .info {
    display: flex;
    justify-content: space-between;
    margin: 76px 0;
    position: relative;
    .lf {
      width: 360px;
      height: 320px;
      box-shadow: 0px 6px 10px rgba(0, 0, 0, 0.5);
      .el-image {
        width: 100%;
        height: 100%;
      }
    }
    .rt {
      width: 1200px;
      .row-two {
        display: flex;
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: 400;
        line-height: 45px;
        .row {
          display: flex;
          width: 460px;
          .title {
            width: 100px;
            text-align-last: justify;
            text-align: justify;
            text-justify: distribute-all-lines;
            color: #999999;
          }
          .dian {
            color: #999999;
          }
          .text {
            width: 340px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
      .row-two:not(:first-child) {
        margin-top: 6px;
      }
      p {
        width: 1038px;
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: 400;
        line-height: 40px;
        color: #333333;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 6;
        overflow: hidden;
      }
    }
    .play-btn {
      position: absolute;
      top: 0;
      right: 280px;
      .img {
        display: inline-block;
        width: 38px;
        height: 38px;
        cursor: pointer;
        .el-image {
          width: 100%;
          height: 100%;
        }
      }
      .img:not(:first-child) {
        margin-left: 30px;
      }
    }
    .qr-code {
      position: absolute;
      top: 0;
      right: 120px;
      width: 120px;
      text-align: center;
      .el-image {
        width: 92px;
        height: 92px;
      }
      p {
        width: 120px;
        height: 28px;
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: bold;
        line-height: 28px;
        color: #333333;
        text-align: center;
        margin-top: 8px;
      }
    }
  }
  .cont {
    display: flex;
    justify-content: space-between;
    margin-top: 40px;
    margin-bottom: 60px;
    .lf {
      width: 648px;
      .head {
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #333333;
      }
      .body {
        margin-top: 40px;
        width: 100%;
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: 400;
        line-height: 32px;
        color: #666666;
      }
    }
    .rt {
      width: 460px;
      .intro {
        .head {
          font-size: 20px;
          font-family: PingFang SC;
          font-weight: bold;
          line-height: 40px;
          color: #333333;
        }
        .body {
          font-size: 20px;
          font-family: PingFang SC;
          font-weight: 400;
          line-height: 33px;
          color: #333333;
          margin-top: 20px;
        }
      }
      .related-songs {
        margin-top: 40px;
        .head {
          font-size: 20px;
          font-family: PingFang SC;
          font-weight: bold;
          line-height: 40px;
          color: #333333;
        }
        .body {
          display: flex;
          flex-wrap: wrap;
          .item {
            width: 140px;
            margin-top: 20px;
            .img {
              width: 140px;
              height: 126px;
              .el-image {
                width: 100%;
                height: 100%;
              }
            }
            h1 {
              font-size: 20px;
              font-family: PingFang SC;
              font-weight: bold;
              line-height: 40px;
              color: #333333;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              margin-top: 10px;
            }
            p {
              font-size: 20px;
              font-family: PingFang SC;
              font-weight: 400;
              line-height: 30px;
              color: #999999;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
          }
          .item:nth-child(2n-1) {
            margin-right: 40px;
          }
        }
      }
      .related-mvs {
        margin-top: 40px;
        .head {
          font-size: 20px;
          font-family: PingFang SC;
          font-weight: bold;
          line-height: 40px;
          color: #333333;
        }
        .body {
          .item {
            width: 460px;
            height: 187px;
            margin-top: 20px;
            cursor: pointer;
            .el-image {
              width: 100%;
              height: 100%;
            }
          }
        }
      }
      .news {
        margin-top: 80px;
        .top {
          display: block;
          width: 460px;
          height: 385px;
          position: relative;
          margin-top: 20px;
          .el-image {
            width: 460px;
            height: 385px;
          }
          p {
            font-size: 20px;
            font-family: PingFang SC;
            font-weight: 400;
            width: 100%;
            height: 66px;
            line-height: 66px;
            background: linear-gradient(
              180deg,
              rgba(0, 0, 0, 0.4) 0%,
              #000000 100%
            );
            color: #ffffff;
            text-align: center;
            position: absolute;
            bottom: 0;
            left: 0;
          }
        }
      }
    }
  }
}
</style>